<template>
    <view :style="themeColor">
        <view class="page" >
    <view class="flex benben-position-layout flex flex-wrap align-center modifyNickname_flex_0"    :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
            <view   class='flex flex-wrap align-center justify-between flex-sub modifyNickname_fd0_0'      >
            <view   class='flex flex-wrap align-center modifyNickname_fd0_0_c0'   @tap.stop="handleJumpDiy" data-type="back" data-url="1"   >
        <text class='modifyNickname_fd0_0_c0_c0'  >{{$t('取消')}}</text>
</view>
    <view   class='flex flex-wrap align-stretch justify-center'      >
        <text class='modifyNickname_fd0_0_c1_c0'  >{{$t('修改昵称')}}</text>
</view>
    <view   class='flex flex-wrap align-center justify-end modifyNickname_fd0_0_c0' :style="{'margin-right':`${ appSystemIdentification == 'Wechat' ?  '30%':''}`}"     >
        <text class='modifyNickname_fd0_0_c2_c0'     @tap="editUserNiknameFunc()" >{{$t('保存')}}</text>
</view>
</view>

        </view>
<view :style="{height: (88+StatusBarRpx)+'rpx'}"  ></view>
<!---flex布局flex布局开始-->
 <view class="flex flex-direction align-stretch benben-flex-layout modifyNickname_flex_1"    >
            <view   class='flex flex-wrap align-center modifyNickname_fd1_0'      >
        <benben-input class='modifyNickname_fd1_0_c0'   type="text" :placeholder="$t('请输入~')" confirm-type="done" :maxlength="7" placeholder-style="color:#999;font-size:36rpx"  @input="valueInspectFunc($event)" v-model="userInfo.nickname"  />
</view>
    <view   class='flex flex-wrap align-center modifyNickname_fd1_1'      >
        <text class='modifyNickname_fd1_1_c0'  >{{$t('请设置2-7个字符，不包含@《/等无效字符哦')}}</text>
</view>
</view>
        
<!---flex布局flex布局结束-->
    
    
        </view>
    </view>
</template>
<script>
    import {validate} from '@/common/utils/validate.js'
    
    export default {
        components:{},
        
        
        data(){
			return {"userInfo":{"invite_code":"","address":"","address_code":"","hobby":"","tags":"","id":"","userlevel_id":"","mobile":"","real_name":"","avatar":"","account":"","email":"","birthday":"","gender":"","create_time":"","user_money":"","freeze_money":"","total_consumption_money":"","score":"","_mobile":"","coupon":"","collection_count":"","browse_count":"","total_money":"","certified":"","nickname":"","is_pay_password":"","follow_count":""},"newUserInfo":{"userinfo":{"id":"","avatar":"","real_name":"","nickname":"","email":"","gender":"","mobile":"","birthday":"","client_id":"","phone":""}},"editname":"editname"};
		},
		computed:{
            themeColor() {
              return this.$store.getters.themeColor
            },
                  /**
     * @returns 
      * Android       安卓
      * IOS       苹果
      * Web       H5 或 pc
      * Wechat       微信小程序
      * Alipay       支付宝小程序
      * Baidu       百度小程序
      * ByteBounce       抖音小程序
      * 360       360小程序
      * FastApp       快应用
    */
    appSystemIdentification() {
      return this.$store.state.appSystemIdentification
    }
		},
		watch:{},
		onLoad(options){
            
		},
        onUnload() {
                
        },
		onReady(){
            
		},
		onShow(){
            this.getUserInfoFunc()
		},
		onHide(){
            
		},
		onResize(){
            
		},
		onPullDownRefresh(){
            
		},
		onReachBottom(e){
            
		},
		onPageScroll(e){
            
		},
		methods:{
                            //获取用户信息
                async getUserInfoFunc(){
                        //请求方法
    //数据验证
    
  let datauserInfo = await this.$api.get(global.apiUrls.post5c78c4772da97, {
    
  });
  
  if (datauserInfo.data.code != 1) {
    this.$message.info(datauserInfo.data.msg);
    return
  } 
  let infouserInfo = datauserInfo.data;
  this.userInfo = infouserInfo.data
  
                },
                //修改用户信息
                async editUserNiknameFunc(){
                                if(!validate(this.userInfo.nickname,'require')){
                 this.$message.info(global.i18n.t('请输入新昵称'));
                 return false;
            }
            if(!validate(this.userInfo.nickname,'length','1,7')){
                 this.$message.info(global.i18n.t('昵称不得超过七个字符'));
                 return false;
            }
    if(this.userInfo.nickname.split('').length<2){
this.$message.info('最少2个字符');
return
}
    //请求方法
    //数据验证
    
  let datanewUserInfo = await this.$api.post(global.apiUrls.post5cb54af125f1c, {
    avatar:this.userInfo.avatar,nickname:this.userInfo.nickname,gender:this.userInfo.gender,birthday:this.userInfo.birthday,autograph:this.userInfo.hobby
  });
  
  if (datanewUserInfo.data.code != 1) {
    this.$message.info(datanewUserInfo.data.msg);
    return
  } 
  let infonewUserInfo = datanewUserInfo.data;
  this.newUserInfo = infonewUserInfo.data
  
                    uni.showToast({
                        title:global.i18n.t('修改成功'),
                        mask:true,
                        icon:'none',
                        duration: 1500
                    });
                uni.$emit('chengeName',this.editname)
                setTimeout(()=>{
                    this.$urouter.navigateBack(1);
      },500)
                },
                //监听输入框输入事件
                 valueInspectFunc(e){
                        var str = e.detail.value
                var newZz = /[`~!@#$%^&*()_\-+=<>?:"{}|,.\/;'\\[\]·~！@#￥%……&*（）——\-+={}|《》？：“”【】、；‘'，。、]/gi;
                if (newZz.test(str)) {
                    this.$nextTick(() => {
                        this.userInfo.nickname = str.replace(newZz, '')

                    })
                    this.$message.info('昵称不能包含特殊字符');
                    return;
                }
                }
		}
    };
</script> 
<style lang="scss" scoped>
           .page{
            width: 100vw;
            overflow-x: hidden;
            min-height: calc(100vh - var(--window-bottom));
            background:#F8F8F8;background-size: 100% auto;
        }
    .modifyNickname_flex_0{
        background:#fff;width:750rpx;height:88rpx;overflow:hidden;z-index:10;top:0rpx;background-size:100% auto !important;
    }
    .modifyNickname_fd0_0_c2_c0{
        color:#2DAF41;font-size:32rpx;font-weight:500;line-height:45rpx;
    }
    .modifyNickname_fd0_0_c1_c0{
        font-size:36rpx;font-weight:700;color:#333;line-height:88rpx;
    }
    .modifyNickname_fd0_0_c0_c0{
        color:#333333;font-size:32rpx;font-weight:500;line-height:45rpx;
    }
    .modifyNickname_fd0_0_c0{
        width:120rpx;
    }
    .modifyNickname_fd0_0{
        padding:0rpx 32rpx 0rpx 32rpx;
    }
    .modifyNickname_flex_1{
        padding:24rpx 32rpx 24rpx 32rpx;
    }
    .modifyNickname_fd1_1_c0{
        color:rgba(155, 161, 170, 1);font-size:24rpx;
    }
    .modifyNickname_fd1_1{
        margin:32rpx 0rpx 0rpx 0rpx;
    }
    .modifyNickname_fd1_0_c0{
        height:50rpx;color:rgba(51, 51, 51, 1);font-size:36rpx;font-weight:700;
    }
    .modifyNickname_fd1_0{
        background:var(--benbenbgColor1);background-size:100% auto !important;border-radius:16rpx;padding:32rpx;
    }
</style>